/*
 * @Author: 玄绮 <shijiahansi@qq.com>
 * @Description:
 * @Date: 2021-10-26 22:44:02
 * @LastEditTime: 2021-11-08 09:28:25
 */
#include <reg52.h>
#include <stdio.h>

#include "51_type.h"
#include "commom.h"
#include "key.h"
#include "gsmg.h"
#include "leddz.h"
#include "tetris/tetris.h"

sbit BEEP = const_P2 ^ 5;

uint8 *p_row = NULL;

void main()
{
    //变量定义
    uint16 i = 1;
    KeyCode key = KEY_UNPRESS;
    uint8 key2 = 0;
    tetris_block_t block2;

    //初始化
    P2 = ~0;
    P0 = 0x00; //初始化 LED 数码管
    block2.col = gled_col_1;
    block2.p_col = block2.p_row = 0;
    block2.index = 0;

    //模块初始化
    leddz_init();

    while (1)
    {
        key = key_scan(0);
        if (key == KEY1_PRESS)
        {
        }
        if (key == KEY2_PRESS)
        {
            i++;
        }
        if (key == KEY3_PRESS)
        {
            i--;
        }
        if (key == KEY4_PRESS)
        {
            leddz_desplay();
        }

        key2 = key_matrix_flip_scan();
        if (key2 != 0)
        {
            i = key2;
            p_row = NULL;
            switch (key2)
            {
            case 1:
                p_row = gled_row2;
                break;
            case 2:
                if (block2.p_row > 0)
                    block2.p_row--;
                break;

            case 3:
                if (block2.index < 3)
                    block2.index++;
                else
                    block2.index = 0;
                break;

            case 6:
                if (block2.p_row < 5)
                    block2.p_row++;
                break;

            case 5:
                if (block2.p_col > 0)
                    block2.p_col--;
                break;
            case 7:
                if (block2.p_col < 1)
                    block2.p_col++;
                break;

            default:
                p_row = NULL;
                break;
            }
        }

        if (p_row)
            leddz_outImg(p_row);
        else
            leddz_outImg_col_test(&block2);
            smg_show_number(i);
    }
}